package edu.hawaii.solardecathlon;

import java.util.HashMap;
import java.util.Map;
import org.apache.wicket.Request;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebSession;

/**
 * Provide a very simple session data structure, which is just a set of string key-value pairs. The
 * session should typically store all of the "model" data for a user.
 * 
 * @author Harry Kwan
 * @author Solar Decathlon Group 7
 * @author Philip Johnson
 */
public class SolarDecathlonApplicationSession extends WebSession {

  /** Support serialization. */
  private static final long serialVersionUID = 1L;

  /** Each user has a set of properties. */
  private Map<String, String> properties = new HashMap<String, String>();
  private Map<String, String> adminProperties = new HashMap<String, String>();
  private Map<String, String> securityProperties = new HashMap<String, String>();
  private Map<String, String> coolingProperties = new HashMap<String, String>();
  private Map<String, String> lightingProperties = new HashMap<String, String>();
  private Map<String, String> mediaProperties = new HashMap<String, String>();
  // private final String up = "Running";
  // private final String down = "Stopped";

  /**
   * Create a new session for this user. Called automatically by wicket. You always need to define
   * this constructor when implementing your own application-specific Session class.
   * 
   * Creates default values for width and height, used by AdminPage.
   * 
   * @param application This application.
   * @param request The request.
   */
  public SolarDecathlonApplicationSession(WebApplication application, Request request) {
    super(request);
    // Initial session values.
    String header = "header";
    String description = "description";
    this.properties.put(header, "Home");
    this.properties.put(description, "Solar Decathlon Home Managment System.<br/>"
        + "Login for more advanced options.");
    this.securityProperties.put("cur_room", "Room");

    // intialize server statuses for prototype
    // use a method to get actual server status in full implementation
    // adminProperties.put("energystat", up);
    // adminProperties.put("lightingstat", up);
    // adminProperties.put("coolingstat", up);
    // adminProperties.put("waterstat", up);
    // adminProperties.put("mediastat", down);
    // adminProperties.put("voicestat", down);
    // adminProperties.put("securitystat", up);

  }

  /**
   * Return the properties instance.
   * 
   * @return The properties.
   */
  public Map<String, String> getProperties() {
    return this.properties;
  }

  /**
   * Get properties for specific page.
   * 
   * @param type Page.
   * @return Properties.
   */
  public Map<String, String> getProperties(String type) {
    if ("admin".equals(type)) {
      return adminProperties;
    }
    return this.properties;
  }

  /**
   * Input properties instance.
   * 
   * @param header The page header.
   * @param description The page description.
   */
  public void setProperties(String header, String description) {
    this.properties.put(header, description);
  }

  /**
   * Set properties for specific page. If no property variable exists, use default as fallback.
   * 
   * @param type Page.
   * @param header Page header.
   * @param description Page description.
   */
  public void setProperties(String type, String header, String description) {
    if ("admin".equals(type)) {
      this.adminProperties.put(header, description);
    }
    else if ("security".equals(type)) {
      this.securityProperties.put(header, description);
    }
    else if ("cooling".equals(type)) {
      this.coolingProperties.put(header, description);
    }
    else if ("lighting".equals(type)) {
      this.lightingProperties.put(header, description);
    }
    else if ("media".equals(type)) {
      this.mediaProperties.put(header, description);
    }
    else {
      this.properties.put(header, description);
    }
  }

}
